using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace QTool.NetFrame
{
    [ExecuteAlways]
    public class FixScene : MonoBehaviour
    {
        public bool LoadOver { get; private set; } = false;
        public List<QNetFrameEntity> idList = new List<QNetFrameEntity>();
        [ContextMenu("更新场景数据")]
        public void FreshSceneInfo()
        {
            idList.RemoveAll((id) => id == null);
            if (Application.isPlaying) return;
            idList.Clear();
            var objs =FindObjectsOfType(typeof(QNetFrameEntity));
            foreach (var obj in objs)
            {
                if (obj is QNetFrameEntity id)
                {
					id.FreshParent();
					if (id.ParentId == null)
					{
						idList.Add(id);
					}
                }
            }
            Debug.Log("FixScene更新了" + idList.Count + "个QNetFrameId 初始数据");
        }
        private void Awake()
        {
            FreshSceneInfo();
            QNetManager.fixScene = this;
        }
      
        public void Load()
        {
            foreach (var id in idList)
            {
                 QNetManager.NetStart(id);
            }
            LoadOver = true;
        }

    }
}
